//
// pops up a tvguide ad
//

function popTvgAdWindow(url, ciid, height, width, scroll, rpthours)
{
	var adcookie = "TVGAD" + ciid;
	
	//
	// check for the cookie - show ad if false
	//
	if(checkAdCookie(adcookie, rpthours))
		return;
	
	//
	// build options string for window
	//
	var opts = "toolbar=no,status=no,location=no,menubar=no,resizable=no";
	opts += ",height=" + height + ",width=" + width + ",scrollbars=" + scroll;
	
	//
	// popup an empty window
	//
	var popwin = window.open("", adcookie, opts);
	
	//
	// set focus to the new window (brings it to the front)
	// this does not work with AOL or Compuserve 2000
	//
	if((navigator.userAgent.indexOf("AOL")<0)&&(navigator.userAgent.indexOf("CS 2000")<0))
		popwin.focus();
		
	//
	// load the page into the popup
	//
	popwin.location = url;
}

function popupAdWin(url, ciid, height, width, scroll)
{
	var adcookie = "TVGAD" + ciid;
	var redir = "/include/ads/popredir.asp?ciid=" + ciid + "&url=" + escape(url);	

	//
	// build options string for window
	//
	var opts = "toolbar=no,status=no,location=no,menubar=no,resizable=no";
	opts += ",height=" + height + ",width=" + width + ",scrollbars=" + scroll;
	
	//
	// popup an empty window
	//
	var popwin = window.open("", adcookie, opts);
	
	//
	// set focus to the new window (brings it to the front)
	// this does not work with AOL or Compuserve 2000
	//
	if((navigator.userAgent.indexOf("AOL")<0)&&(navigator.userAgent.indexOf("CS 2000")<0))
		popwin.focus();
		
	//
	// load the page into the popup
	//
	popwin.location = redir;
}


//
// gets the domain of this server for cookies
//
function getServerDomainName()
{
	var strHTP	= new String("http://");
	var strURL	= new String(document.location);

	//
	// convert string to lower case
	//
	strURL = strURL.toLowerCase();

	//
	// remove the "http://"
	//
	var n = strURL.indexOf(strHTP);
	if (n >= 0)
		strURL = strURL.substring(n + strHTP.length);
		
	//
	// remove page and querystring
	//
	n = strURL.indexOf("/");
	if (n >= 0)
		strURL = strURL.substring(0, n);
	
	//
	// extract domain by looking for last two dots
	//	
	n = strURL.lastIndexOf(".");
	if (n > 0)
	{
		//
		// got first dot - look for another
		//
		n = strURL.lastIndexOf(".", n-1);
		if (n >= 0)
			strURL = strURL.substring(n);	
		else
			strURL = "." + strURL;	
	}
	return strURL;
}



//
// sets a cookie that expires in expdays
//
function checkAdCookie(name, hours)
{
	//
	// if hours == 0 just show the ad without setting a cookie
	//
	if(hours==0)
		return false;

	//
	// get the cookies collection
	//
	var strCookie = document.cookie;
		
	//
	// if the cookie is present do not show the ad
	//	
	if(strCookie.indexOf(name)>=0)
		return true;
	
	//
	// no cookie - set cookie and show the ad
	//	
	var expiration = new Date((new Date()).getTime() + hours * 3600000);
	strCookie = name + "=y; expires=" + expiration.toGMTString() + "; ";
	strCookie += "path=/; domain=" + getServerDomainName();
	document.cookie = strCookie;

	return false;
}

